package com.sunbird.crm.base.contorller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @ClassName BaseContorller
 * @Descriptiom TODO
 * @Author Sunbird
 * @Date 2019/8/24 11:20
 * @Version 1.0
 **/
public abstract class BaseContorller {

    protected  Logger LOGGER = LoggerFactory.getLogger(this.getClass());



    /**
     * @Author Sunbird
     * @Description 从thread local 获取网络上下文
     * @Date  2019/8/24
     * @Param
     * @return
     **/

    public HttpServletRequest getServletRequest(){
        RequestAttributes requestAttribute = RequestContextHolder.getRequestAttributes();
        ServletRequestAttributes servletRequestAttributes;
        if (requestAttribute  instanceof  ServletRequestAttributes){
            servletRequestAttributes = (ServletRequestAttributes) requestAttribute;
            return servletRequestAttributes.getRequest();
        }
        return null;
    }
    /**
     * @Author Sunbird
     * @Description 获取当前客户端session 对象
     * @Date  2019/8/24
     * @Param
     * @return
     **/
   public HttpSession getSession(){
       return getServletRequest().getSession();
   }
}
